/**
 * 
 */
package truerefactor.graph;

/**
 * TypePair - A Parameter class used to hold information regarding type of
 * parameters in a MethodNode
 * 
 * @author Isaac Griffith
 */
public class TypePair {

    /**
     * The type name
     */
    private String type;
    /**
     * Primitive flag
     */
    private boolean isPrimitive;

    /**
     * Constructs a new TypePair instance with the given type name and value for
     * the primitive flag
     * 
     * @param type
     *            type name
     * @param isPrimitive
     *            primitive flag value
     */
    public TypePair(String type, boolean isPrimitive)
    {
        this.type = type;
        this.isPrimitive = isPrimitive;
    }

    /**
     * @return the name of the type
     */
    public String getType()
    {
        return type;
    }

    /**
     * Sets the type parameter to the value provided
     * 
     * @param type
     *            new value of the type parameter
     */
    public void setType(String type)
    {
        this.type = type;
    }

    /**
     * @return true if the primitive flag is set, false otherwise
     */
    public boolean isPrimitive()
    {
        return isPrimitive;
    }

    /**
     * Sets the primitive Flag to be the value provided
     * 
     * @param isPrimitive
     *            new value for the primitive flag
     */
    public void setPrimitive(boolean isPrimitive)
    {
        this.isPrimitive = isPrimitive;
    }

    /*
     * (non-Javadoc)
     * @see java.lang.Object#clone()
     */
    @Override
    protected Object clone() throws CloneNotSupportedException
    {
        TypePair ret = new TypePair(new String(type), isPrimitive);

        return ret;
    }

    /*
     * (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + (isPrimitive ? 1231 : 1237);
        result = prime * result + ((type == null) ? 0 : type.hashCode());
        return result;
    }

    /*
     * (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj)
    {
        if (this == obj)
        {
            return true;
        }
        if (obj == null)
        {
            return false;
        }
        if (!(obj instanceof TypePair))
        {
            return false;
        }
        TypePair other = (TypePair) obj;
        if (isPrimitive != other.isPrimitive)
        {
            return false;
        }
        if (type == null)
        {
            if (other.type != null)
            {
                return false;
            }
        }
        else if (!type.equals(other.type))
        {
            return false;
        }
        return true;
    }
}
